package com.house.controller;


import com.house.common.Result;
import com.house.entity.LetterIntent;
import com.house.service.LetterIntentService;
import com.house.util.ResultUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author asus
 * @since 2021-02-28
 */ 
@RestController
@RequestMapping("/letterIntent")
public class LetterIntentController {

    @Resource
    private LetterIntentService letterIntentService;

    @PostMapping("insertNewLetterIntent")
    public Result insertNewLetterIntent(@RequestBody LetterIntent letterIntent)
    {
        Integer data = letterIntentService.insertNewLetterIntent(letterIntent);
        if(data != 0)
        {
            return ResultUtil.success(202, data);
        }
        return ResultUtil.failure(502, null);
    }

    @GetMapping("selectLetterIntent/{hostId}")
    public Result selectLetterIntent(@PathVariable("hostId") Integer hostId) {
        List<LetterIntent> letterIntents = letterIntentService.selectLetterIntent(hostId);
        if (letterIntents != null)
        {
            return ResultUtil.success(201, letterIntents);
        }
        return ResultUtil.failure(501, "失败");
    }
}
